home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / lha_axeman / append.c next >
C/C++ Source or Header  |  1995-09-01  |  2KB  |  96 lines

  1. /***********************************************************
  2.     append.c -- append to archive
  3. ***********************************************************/
  4. #include "lharc.h"
  5. #include "intrface.h"
  6.  
  7. #define MAX_INDICATOR_COUNT    64
  8. long        indicator_count;
  9. long        indicator_threshold;
  10.  
  11. extern int quiet;
  12. extern int compress_method;
  13. extern long int reading_size;
  14. extern unsigned short dicbit;
  15.  
  16. struct interfacing interface;
  17.  
  18. int encode_lzhuf(FILE *infp, FILE *outfp, long size, long *original_size_var, long *packed_size_var, char *name, char *hdr_method)
  19. {
  20.     static int method = -1;
  21.  
  22.     if(method < 0)
  23.   {
  24.         method = compress_method;
  25.         if(method > 0) method = encode_alloc(method);
  26.     }
  27.  
  28.     interface.method = method;
  29.  
  30.     if(interface.method > 0)
  31.   {
  32.         interface.infile = infp;
  33.         interface.outfile = outfp;
  34.         interface.original = size;
  35.         start_indicator (name, size, "Freezing",1<<dicbit);
  36.         encode(&interface);
  37.         *packed_size_var = interface.packed;
  38.         *original_size_var = interface.original;
  39.     }
  40.   else
  41.   {
  42.       copyfile(infp, outfp, size, 1);
  43.       *packed_size_var = *original_size_var = size;
  44.     }
  45.     bcopy("-lh -", hdr_method, 5);
  46.     hdr_method[3] = interface.method + '0';
  47.  
  48.     finish_indicator2 (name, "Frozen", (int)((*packed_size_var * 100L) / *original_size_var ));
  49.     return crc;
  50. }
  51.  
  52. void start_indicator(char *name, long size, char *msg, long def_indicator_threshold)
  53. {
  54.     long    i;
  55.     int    m;
  56.  
  57.     if(quiet) return;
  58.  
  59.     m = MAX_INDICATOR_COUNT - strlen (name);
  60.     if(m < 0)    m = 3;        /* (^_^) */
  61.     printf ("\r%s\t- %s :  ", name, msg);
  62.  
  63.     indicator_threshold = 0;
  64. //((size+(m*def_indicator_threshold-1))(m*def_indicator_threshold)*def_indicator_threshold);
  65.  
  66.     if(indicator_threshold)
  67.         {
  68.         i = ((size + (indicator_threshold - 1)) / indicator_threshold);
  69.     } else {
  70.         i = 0;
  71.         }
  72.  
  73.     while(i--) putchar('.');
  74.     indicator_count = 0;
  75.     printf("\r%s\t- %s :  ", name, msg);
  76.     fflush(stdout);
  77.     reading_size = 0L;
  78. }
  79.  
  80. void finish_indicator2(char *name, char *msg, int pcnt)
  81. {
  82.     if(quiet) return;
  83.  
  84.     if(pcnt > 100) pcnt = 100;    /* (^_^) */
  85.     printf("\r%s\t- %s(%d%%)\n", name, msg, pcnt);
  86.     fflush(stdout);
  87. }
  88.  
  89. void finish_indicator(char *name, char *msg)
  90. {
  91.     if(quiet) return;
  92.  
  93.     printf("\r%s\t- %s\n", name, msg);
  94.     fflush(stdout);
  95. }
  96.